<?php
// 本类由系统自动生成，仅供测试用途
namespace Admin\Controller;
use Think\Controller;
class MenuController extends baseActionController {
	public function adminlist(){
		
		//$this->yuanq();
		$data1=M("admin")->count();
		$data1=ceil($data1/3);
		$info=M("zhw")->select();
		$data=M("admin")->select();
		$this->assign('data1',$data1);// 赋值分页输出
		$this->assign('data',$data);// 赋值分页输出
		$this->assign('info',$info);// 赋值分页输出		
		$this->display();
	}
	public function cdminlist(){
		
		@$page = max(1, intval($_GET["p"]));
		$pagesize=3;
		$startindex=($page-1)*$pagesize;
		
		$list  = M('admin')->limit($startindex,$pagesize)->select();
		$list1 = M('zhw')->select();
		
		foreach ($list as $v){
			foreach ($list1 as $vo){
				if ($v['role']==$vo['zid']) {
					$qwe=$vo['zname'];
				}
			}
				
			if ($v['xid']==0) {
				$qwe2='<td class="admin-status">
				<span class="label label-success">已启用</span>
				</td>';
			}else{
				$qwe2='<td class="admin-status">
				<span class="label">已停用</span>
				</td>';
			}
		
			$date1=date('Y-m-d H:i:s',$v['atime']);
			$vid="value='{$v['aid']}'" ;
			$asd='<td><input type="checkbox"'.$vid.'name=""></td>';
			$id="<th >{$v['aid']}</th>";
			$aname="<th >{$v['aname']}</th>";
			$niname="<th >{$v['niname']}</th>";
			$jue="<th >{$qwe}</th>";
			$date2="<th >{$date1}</th>";
			$arr=array(id=>$v['aid']);
			$asda=U('ting',$arr);
			$asda1=U('edit',$arr);
			$asda2=U('del',$arr);
				
				
			$asd="<td class='f-14 admin-manage'><a style='text-decoration:none'  href='{$asda}' title='停用'><i class='icon-hand-down'></i></a>
			<a title='编辑' href='{$asda1}'  class='ml-5' style='text-decoration:none'><i class='icon-edit'></i></a>
			<a title='删除'  name='del' class='ml-5' href='{$asda2}' style='text-decoration:none'><i class='icon-trash'></i></a></td>";
				
			$trs.='<tr class="text-c">'.'<td><input type="checkbox" value="{$v.aid}" name=""></td>'.$id.$aname.$niname.$jue.$date2.$qwe2.$asd.'</tr>';
				
		}
		
		
			$data = $trs;
			$this->ajaxReturn($data);
		
		
	}

	
	
	
   public function adminrole(){
   	//$this->yuanq();
    	$this->display();
    }
    public function adminpermission(){
    	$this->yuanq();
    	
    	$info1=M("funct")->where('even=0')->select();
    	$data1=M("funct")->where('even=1')->select();
    	
    	 

   
    	$data=M("funct")->where('even=1')->select();
    	$info=M("zhw")->select();
    	$this->assign('info',$info);// 赋值分页输出
    	$this->assign('data',$data);// 赋值分页输出
    	$this->assign('info1',$info1);// 赋值分页输出
    	$this->assign('data1',$data1);// 赋值分页输出
    	
    	$this->display();
    }
    
  
    
    public function zwadd(){
    	$this->yuanq();
    	
    	$info=M("funct")->where('even=0')->select();
    	$data=M("funct")->where('even=1')->select();
    	$this->assign('info',$info);// 赋值分页输出
    	$this->assign('data',$data);// 赋值分页输出
    	$this->display();
    }
    public function doxadd(){
    	
    	$qun=implode($_POST['zquan'],',');
    	$date['zname']=$_POST['zname'];
    	$date['zquan']=$qun;
    	$info=M("zhw")->add($date);
    	
    	if ($info) {
    	$this->success('修改成功',U('adminpermission'));
    	}else{
    	$this->error('修改失败',U('adminpermission'));
    	}
    }
    
    public function zwedit(){
    	$this->yuanq();
    	$id=I('id');
    	$red=M("zhw")->find($id);
    	
    	$info=M("funct")->where('even=0')->select();
    	$data=M("funct")->where('even=1')->select();
    	
    	$this->assign('red',$red);// 赋值分页输出
    	$this->assign('info',$info);// 赋值分页输出
    	$this->assign('data',$data);// 赋值分页输出
    	
    	$this->display();
    
    }
    public function dozwedit(){
    	
    	 $_POST['zquan']=implode($_POST['zquan'], ',');
    	$info=M("zhw")->save($_POST);
    
    	if ($info) {
    		$this->success('修改成功',U('adminpermission'));
    	}else{
    		$this->error('修改失败',U('adminpermission'));
    	}
    }
    
    public function zwdel(){
    	
 		$uid = I('uid');
		$res = M('zhw')->delete($uid);
		$r = array();
		if($res){
			$r['msg']='删除成功';
			$r['status']=true;
		}else{
			$r['msg']='删除失败';
			$r['status']=false;
		}
		$this->ajaxReturn($r);
    }
    
    public function add(){
    	//$this->yuand();
    
    	$date['aname']=$_POST['uname'];
    	$date['apwd']=md5($_POST['pwd']);
    	$date['role']=$_POST['role'];
    	$date['niname']=$_POST['aniname'];
    	$date['atime']=time();
    	$info=M("admin")->add($date);
    	if ($info) {
    		$this->success('新增成功');
    	}else{
    		 $this->error('新增失败');
    	}   
    }
    
    public function del(){
    	//$this->yuand();
    
    	$id = $_GET['id'];
    	$res = M('admin')->delete($id);
    	
    	if($res){
    		$this->success('删除成功');
    	}else{
    		$this->error('删除失败');
    	} 
    }
    
    public function ting(){
    	//$this->yuand();
    	$id = I('id');
    	
    	$qaz=M('admin')->find($id);
    	if ($qaz['xid']==0) {
    		$data['xid']=1;
    	}else{
    		$data['xid']=0;
    	}
    
    	
    	$data['aid']=$id;
    	
    	
    	$res = M('admin')->save($data);
    	$r = array();
    	if($res){
    		$this->success('修改成功');
    	}else{
    		$this->error('修改失败');
    	}
    }
   
    public function edit(){
    	//$this->yuanq();
    	$id = I('id');
    	$res = M('admin')->find($id);
    	$this->assign('res',$res);// 赋值分页输出
    	$this->display();
    }
 
    public function doedit(){
    	$_POST['apwd']=md5($_POST['apwd']);
    	$_POST['ctime']=time();
    	$res = M('admin')->save($_POST);
    	if($res){
    		$this->success('修改成功',U('adminlist'));
    	}else{
    		$this->error('修改失败',U('adminlist'));
    	}
    
    }
    

     
}